using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Diomede.SDK;

namespace WindowsTest
{
    public partial class Form1 : Form
    {
        ISession session;
        string username = string.Format("user_{0}",DateTime.Now.ToString("yyyyMMddhhmmss"));
        string password = "password914";
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void btnCreateUser_Click(object sender, EventArgs e)
        {
            session = new Session();
            string email = string.Format("{0}@email.com", username);
            if ((session as IAccountManagement).Create(username, password, email).Status != Diomede.SDK.Enums.ExecutionResults.Success)
            {
                MessageBox.Show("Fail to create user.");
                return;
            }
            btnCreateUser.Enabled = false;
            //groupBox.Enabled = true;
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (session == null)
                session = new Session();

            LoginForm frm = new LoginForm(username, password);
            if (frm.ShowDialog(this) == DialogResult.OK)
            {
                username = frm.UserName;
                password = frm.Password;

                if (session.Login(username, password).Status != Diomede.SDK.Enums.ExecutionResults.Success)
                {
                    MessageBox.Show("Login fail.");
                    return;
                }
                btnLogin.Enabled = false;
                btnLogout.Enabled = true;
                btnUpload.Enabled = true;
            }
        }

        private void btnLogout_Click(object sender, EventArgs e)
        {
            session.Logout();
            btnLogin.Enabled = true;
            btnLogout.Enabled = false;
            btnUpload.Enabled = false;
        }

        private void btnUpload_Click(object sender, EventArgs e)
        {
            (session as IFileManagement).OpenUploadWindow(false);
        }

        private void btnCreateSpecificUser_Click(object sender, EventArgs e)
        {
            UserInfoForm frm = new UserInfoForm();
            if (frm.ShowDialog(this) == DialogResult.OK)
            {
                username = frm.UserName;
                password = frm.Password;
                btnCreateUser.Enabled = false;
                //groupBox.Enabled = true;
            }

        }
        int l = 1;
        private void button1_Click(object sender, EventArgs e)
        {
            IAccountManagement acc = session as IAccountManagement;
            com.diomede.services.data.UserInfo info = new com.diomede.services.data.UserInfo();
            info.cardNumber = "111122223333123"+ l.ToString();
            acc.UpdateAccountInfo(info);
            ISessionExecResult result = acc.GetAccountInfo();
            l += 1;
        }
    }
}